﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Data.SqlClient;
using System.Data;
using Media.Core.Entities;
using Media.Core.Data;
using Media.Core.Models.Admin;

namespace Media.Core.Helpers.Main
{
    public class GetDirectory
    {
        private static Database db = new Database();


        public static string UserLocationName(string Name, string UserId)
        {
            return(db.Linq.Single<Main_Directories_User>(s => s.UserId == UserId && s.Type == Name).Type);

            //return (from m in db.Main_Directories_Users
            //        where m.UserId == UserId & m.Type == Name
            //        select m.Type).Single();
        }

        public static string UserLocation(string Name, string UserId)
        {
            return (db.Linq.Single<Main_Directories_User>(s => s.UserId == UserId && s.Type == Name).Directory);

            //return (from m in db.Main_Directories_Users
            //        where m.UserId == UserId & m.Type == Name
            //        select m.Directory).Single();
        }

        public static string LocationName(string Name)
        {
            return (db.Linq.Single<Main_Directory>(s => s.Name == Name).Name);

            //return (from m in db.Main_Directory
            //        where m.Name == Name
            //        select m.Name).Single();
        }

        public static string Location(string Name)
        {
            return (db.Linq.Single<Main_Directory>(s => s.Name == Name).Directory);

            //var dir = (from m in db.Main_Directory
            //        where m.Name == Name
            //        select m.Directory).Single();

            //return dir;
        }

        public static DirectoryArray All()
        {
            ArrayList paramsList = new ArrayList
            {
                new SqlParameter("Name", "All")
            };

            var MovieDir = Data.Connections.GetDataTable("Main_Get_Directories", paramsList);

            var Directories = new DirectoryArray();

            foreach (DataRow Directory in MovieDir.Rows)
            {
                Directories.Directories.Add(new Directory
                {
                    Name = Directory["Name"].ToString(),
                    MediaDirectory = Directory["Directory"].ToString()
                });
            }
            return Directories;
        }
    }
}